package com.citycloud.ccuap.tc.sync.controller;

import com.citycloud.ccuap.commons.json.JSONData;
import com.citycloud.ccuap.commons.log.LogHelper;
import com.citycloud.ccuap.commons.openapi.controller.base.BaseController;
import com.citycloud.ccuap.commons.sys.deptment.IDeptmentService;
import com.citycloud.ccuap.commons.sys.entity.SysDeptment;
import com.citycloud.ccuap.commons.sys.entity.SysGroup;
import com.citycloud.ccuap.commons.sys.group.IGroupService;
import com.citycloud.ccuap.commons.sys.user.IUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/syncData")
public class SyncDataController extends BaseController {

    protected static LogHelper logger = new LogHelper(SyncDataController.class);

    @Resource
    private IGroupService groupService;

    @Resource
    private IDeptmentService deptmentService;

    @Resource
    private IUserService userService;

    @ApiOperation("组织机构信息")
    @RequestMapping(value = "/groupInfo", method = {RequestMethod.GET, RequestMethod.POST})
    public JSONData groupInfo() throws Exception {
        List<SysGroup> groupList = groupService.selectList();

        JSONData jsonData = new JSONData(groupList);
        return jsonData;
    }

    @ApiOperation("部门信息")
    @RequestMapping(value = "/deptInfo", method = {RequestMethod.GET, RequestMethod.POST})
    public JSONData deptInfo() throws Exception {
        Long groupId = getLongParameter("groupId");
        List<SysDeptment> deptList;

        if (groupId == null) {
            deptList = deptmentService.selectList();
        } else {
            deptList = deptmentService.findByGroupId(groupId);
        }
        JSONData jsonData = new JSONData(deptList);
        return jsonData;
    }

    @ApiOperation("组织机构信息")
    @RequestMapping(value = "/userInfo", method = {RequestMethod.GET, RequestMethod.POST})
    public JSONData userInfo() throws Exception {
        Long groupId = getLongParameter("groupId");
        Long deptId = getLongParameter("deptId");
        List<Map<String, Object>> list = userService.getUserListByGroupIdAndDeptId(groupId, deptId);
        JSONData jsonData = new JSONData(list);
        return jsonData;
    }
}
